<div class="layui-fluid layui-anim website-anim" id="website-choose" lay-title="选择学科分类">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <input type="hidden" id="topicClassifyCode_subject" name="topicClassifyCode_subject" autocomplete="off"
                           class="layui-input" data-th-value="${topicClassifyCode}"/>
                    <input type="hidden" id="topicId_subject" name="topicId_subject" autocomplete="off" class="layui-input"
                           data-th-value="${topicId}"/>
                    <input type="hidden" id="planId_subject"  name="planId_subject" autocomplete="off" class="layui-input"
                           data-th-value="${planId}"/>
                    <div id = "showTip"></div>
                    <table lay-filter="chooseSubjectTable" lay-data="{id: 'chooseSubjectTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarSave">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">保存</button>

        <button id = "addSubjectData" th:if="${topicClassifyCode}=='entrust'" class="layui-btn layui-btn-sm" lay-event="addData">增加</button>
    </div>
</script>
<script type="text/html" id="expert-class">
    {{#
    var dict=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'table', 'website','dict'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            dict = layui.dict,
            $view = $('#website-choose'),
            tableIns;
        table =  $.extend(table, {config: {checkName: 'choose'}});
        initTable();
        //头工具栏事件
        table.on('toolbar(chooseSubjectTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            var data = checkStatus.data;
            switch(obj.event){
                case 'getCheckData':
                     //获取选中行数据
                    website.ajaxPost(ctx + 'reviews/' + $("#planId_subject").val() + '/' + $("#topicId_subject").val() + '/classify', JSON.stringify(data), function () {
                        var currentUrl = window.location.hash.replace('#', '');
                        website.view.tab.del(currentUrl);
                        if($("#topicClassifyCode_subject").val() === 'entrust'){
                            $('#website-topic-entrust').find('#query').click();
                        } else {
                            $('#website-topic-annual').find('#query').click();
                        }
                        website.alert.success('操作成功');
                    });
                    break;
                case 'addData':
                    website.modal.open('增加学科', 'biz/review/' + $("#planId_subject").val() + '/' + $("#topicId_subject").val() + '/addSubject', {
                        area: $(window).width() <= 750 ? '95%' : '50%'
                    });
                    break;
            };
        });

        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'chooseSubjectTable',
                limit: 2000,
                toolbar: '#toolbarSave',
                defaultToolbar:[],
                page: false,
                /* url: ctx + $("#planId_subject").val() + '/'+ $("#topicId_subject").val() + '/topicSubjectDetail',*/
               cols: [[
                    {type: 'numbers', title: '序号'},
                    {field: 'name', title: '选题名称', minWidth: 100},
                    {title: '学科分类', templet: '#expert-class'},
                    {field: 'num', title: '数量'},
                    {type: 'checkbox', field:'choose'}
                ]],
                data:[]
            });

            website.get(ctx + $("#planId_subject").val() + '/'+ $("#topicId_subject").val() + '/topicSubjectDetail', null, function (result) {
                if(result.data && result.data.list) {
                    table.reload('chooseSubjectTable', {data: result.data.list});
                    if(result.data.list.length < 1){
                        debugger
                        $("#showTip").html("<span style='color:red;font-weight:bold'>注：该选题没有申报课题，请点击保存！</span>");
                        $("#addSubjectData").hide();
                    }
                }
            });
        }
    })
</script>